package com.jkl.controller.home;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jkl.entity.BaseResponseDTO;
import com.jkl.entity.home.CapabilityResponseEntity;
import com.jkl.entity.home.HomeCapabilityMappingEntity;
import com.jkl.entity.home.HomeRequestEntity;
import com.jkl.service.home.capabilityAnalysisInter.CapabilityAnalysisServiceNew;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.List;
import java.util.Map;


/**
 * @author zjj
 * @date  2019/9/2 16:00
 * @Description  ${描述一个类的相关信息}
 */
@RestController
@RequestMapping("/jky/home/analysis")
@Slf4j
public class CapabilityAnalysisController {
//    @Autowired
//    private CapabilityAnalysisService capabilityAnalysisService;
     @Autowired
     private CapabilityAnalysisServiceNew capabilityAnalysisService;
    /**
     *能力平衡分析
     */
    @PostMapping("/abilityBalanceAnalysis")
    public BaseResponseDTO getCoverageTrend(@RequestBody HomeRequestEntity homeRequestEntity) {
        BaseResponseDTO returnData = new BaseResponseDTO();
        CapabilityResponseEntity abilityBalanceAnalysis = capabilityAnalysisService.getAbilityBalanceAnalysis(homeRequestEntity);
        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(abilityBalanceAnalysis));
        returnData.setReturnData(jsonObject);
        return returnData;
    }

    /**
     *处置结构分析
     */
    @PostMapping("/disposalStructureAnalysis")
    public BaseResponseDTO getCoverageSituation(@RequestBody HomeRequestEntity homeRequestEntity) {
        BaseResponseDTO returnData = new BaseResponseDTO();
        Map<String, Object> disposalStructureAnalysis = capabilityAnalysisService.getDisposalStructureAnalysis(homeRequestEntity);
        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(disposalStructureAnalysis));
        returnData.setReturnData(jsonObject);
        return returnData;
    }
    /**
     * 年度建设进度饼状图
     */
    @PostMapping("/constructionProgressCircle")
    public BaseResponseDTO getAreaCoverageRanking(@RequestBody HomeRequestEntity homeRequestEntity) {
        BaseResponseDTO returnData = new BaseResponseDTO();
        CapabilityResponseEntity constructionProgressCircle = capabilityAnalysisService.getConstructionProgressCircle(homeRequestEntity);
        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(constructionProgressCircle));
        returnData.setReturnData(jsonObject);
        return returnData;
    }
    /**
     *年度建设进度柱状图
     */
    @PostMapping("/constructionProgressHistogram")
    public BaseResponseDTO getHarmLesscircleAnalysis(@RequestBody HomeRequestEntity homeRequestEntity) {
        BaseResponseDTO returnData = new BaseResponseDTO();
        List<CapabilityResponseEntity> constructionProgressHistogram = capabilityAnalysisService.getConstructionProgressHistogram(homeRequestEntity);
        JSONObject returnJson = new JSONObject();
        JSONArray  constructionProgressHistogramArray = (JSONArray) JSONArray.toJSON(constructionProgressHistogram);
        returnJson.put("list", constructionProgressHistogramArray);
        returnData.setReturnData(returnJson);
        return returnData;
    }

    /**
     *处理能力预测
     */
    @PostMapping("/processingForecast")
    public BaseResponseDTO getTimedDemonstration(@RequestBody HomeRequestEntity homeRequestEntity) {
        BaseResponseDTO returnData = new BaseResponseDTO();
        List<CapabilityResponseEntity> processingForecast = capabilityAnalysisService.getProcessingForecast(homeRequestEntity);
        JSONObject returnJson = new JSONObject();
        JSONArray processingForecastArray = (JSONArray) JSONArray.toJSON(processingForecast);
        returnJson.put("list", processingForecastArray);
        returnData.setReturnData(returnJson);
        return returnData;
    }


    /**
     * gis展示
     */
    @PostMapping("/gis")
    public BaseResponseDTO getGisAnalysis(@RequestBody HomeRequestEntity homeRequestEntity) {
        BaseResponseDTO returnData = new BaseResponseDTO();
        CapabilityResponseEntity gis = capabilityAnalysisService.getGisNew(homeRequestEntity);
        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(gis));
        returnData.setReturnData(jsonObject);
        return returnData;
    }

    /**
     * 全省能力分析
     * @param homeRequestEntity
     * @return
     */
    @PostMapping("/allProvinceAnalysis")
    public BaseResponseDTO allProvinceAnalysis(@RequestBody HomeRequestEntity homeRequestEntity) throws ParseException {
        BaseResponseDTO baseResponseDTO = new BaseResponseDTO();
        List<HomeCapabilityMappingEntity> resultList = capabilityAnalysisService.allProvinceAnalysis(homeRequestEntity);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("resultList", resultList);
        baseResponseDTO.setReturnData(jsonObject);
        return baseResponseDTO;
    }


    /**
     * 各市能力分析
     * @param homeRequestEntity
     * @return
     */
    @PostMapping("/cityAnalysis")
    public BaseResponseDTO cityAnalysis(@RequestBody HomeRequestEntity homeRequestEntity) throws ParseException {
        BaseResponseDTO baseResponseDTO = new BaseResponseDTO();
        List<HomeCapabilityMappingEntity> resultList = capabilityAnalysisService.cityAnalysis(homeRequestEntity);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("resultList", resultList);
        baseResponseDTO.setReturnData(jsonObject);
        return baseResponseDTO;
    }

    /**
     * 转运设施设备
     * @param homeRequestEntity
     * @return
     */
    @PostMapping("/shipEquipmentAnalysis")
    public BaseResponseDTO shipEquipmentAnalysis(@RequestBody HomeRequestEntity homeRequestEntity) {
        BaseResponseDTO baseResponseDTO = new BaseResponseDTO();
        List<HomeCapabilityMappingEntity> resultList = capabilityAnalysisService.shipEquipmentAnalysis(homeRequestEntity);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("resultList", resultList);
        baseResponseDTO.setReturnData(jsonObject);
        return baseResponseDTO;
    }

    /**
     * 终端处置
     * @return
     */
    @PostMapping("/endDeal")
    public BaseResponseDTO endDeal(@RequestBody HomeRequestEntity homeRequestEntity) {
        BaseResponseDTO result = new BaseResponseDTO();
        List<HomeCapabilityMappingEntity> resultList = capabilityAnalysisService.endDeal(homeRequestEntity);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("resultList", resultList);
        result.setReturnData(jsonObject);
        return result;
    }

    /**
     * 终端处置---获取区域下的项目列表
     * @param homeRequestEntity
     * @return
     */
    @PostMapping("/endDealGetProjectList")
    public BaseResponseDTO endDealGetProjectList(@RequestBody HomeRequestEntity homeRequestEntity) {
        BaseResponseDTO result = new BaseResponseDTO();
        List<HomeCapabilityMappingEntity> resultList = capabilityAnalysisService.endDealGetProjectList(homeRequestEntity);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("resultList", resultList);
        result.setReturnData(jsonObject);
        return result;
    }

    /**
     * 终端处置---获取项目详情
     * @param homeRequestEntity
     * @return
     */
    @PostMapping("/endDealGetProject")
    public BaseResponseDTO endDealGetProject(@RequestBody HomeRequestEntity homeRequestEntity) {
        BaseResponseDTO result = new BaseResponseDTO();
        String rowId = homeRequestEntity.getRowId();
        HomeCapabilityMappingEntity resultEntity = capabilityAnalysisService.endDealGetProject(rowId);
        result.setReturnData(JSONObject.parseObject(JSON.toJSONString(resultEntity)));
        return result;
    }
}
